package com.kstudio.videocapture.util.bitmapload;

import android.graphics.Bitmap;
import android.util.LruCache;

public class BitmapLruCacheMemory implements BitmapLruCache {

    private LruCache<String, Bitmap> lruCache;

    public BitmapLruCacheMemory(int maxMemory) {
        lruCache = new LruCache<String, Bitmap>(maxMemory) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                    // The cache size will be measured in bytes
                    return bitmap.getByteCount();
                }
            };
    }

    @Override
    public void put(String key, Bitmap bm) {
        if (bm == null)
            return;
        lruCache.put(key, bm);
    }

    @Override
    public Bitmap get(String key) {
        return lruCache.get(key);
    }

    @Override
    public void remove(String key) {
        lruCache.remove(key);
    }

    @Override
    public void clear() {
        lruCache.evictAll();
    }

}
